import 'package:fate_blind_box/network/http_request.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';

import 'my_pub_act_model.dart';

class MyActListController extends GetxController {
  String myPubViewId = 'myPubViewId';
  String attendViewId = 'attendViewId';
  String expireViewId = 'expireViewId';

  List pubList = [];
  List attendList = [];
  List expireList = [];

  void getMyPublishData() async {
    Map <String, dynamic>dataMap ={'memberId':Provider.memberId};
    var myPubMap =
        await HttpRequest.request('member/activity/postsList', params: dataMap);
    if (myPubMap is Map) {
      MyPubActModel resPubModel = MyPubActModel.fromJson(myPubMap);
      if (pubList.isNotEmpty) {
        pubList.clear();
      }
      pubList.addAll(resPubModel.data ?? []);
      update([myPubViewId]);
    }
    var myAttendMap =
        await HttpRequest.request('member/activity/joinList', params: dataMap);
    if (myAttendMap is Map) {
      MyPubActModel attendModel = MyPubActModel.fromJson(myAttendMap);
      if (attendList.isNotEmpty) {
        attendList.clear();
      }
      attendList.addAll(attendModel.data ?? []);
      update([attendViewId]);
    }
    var hasExpiredMap =
        await HttpRequest.request('member/activity/endedList', params: dataMap);
    if (hasExpiredMap is Map) {
      MyPubActModel hasExpiredModel = MyPubActModel.fromJson(hasExpiredMap);
      if (expireList.isNotEmpty) {
        expireList.clear();
      }
      expireList.addAll(hasExpiredModel.data ?? []);
      update([expireViewId]);
    }
  }
}
